﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminFunction.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="BitPortal.Admin.Media.Media.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function getImagePreview(img, url, thumb, type) {
            var imageSrc
            if (type == "Image") {
                imageSrc = url;
            }
            else if (type == "Video") {
                imageSrc = thumb;
            }
            else if (type == "Flash") {
                imageSrc = "/Images/flash_player.png";
            }
            else if (type == "Audio") {
                imageSrc = "/Images/audio_x_monkey.png";
            }
            if (img.src != imageSrc) { // don't get stuck in an endless loop
                img.src = imageSrc;
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="TopBarHolder" runat="server">
    <ext:ButtonGroup ID="ButtonGroup1" runat="server" Layout="ToolbarLayout">
        <Items>
            <ext:Button runat="server" ID="btnAdd" Text="Thêm media" Icon="PhotoAdd" Scale="Medium"
                CausesValidation="false">
                <DirectEvents>
                    <Click OnEvent="btnAdd_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnEdit" Text="Sửa media" Icon="PhotoEdit" Scale="Medium"
                CausesValidation="false">
                <DirectEvents>
                    <Click OnEvent="btnEdit_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnDelete" Text="Xóa media" Icon="PhotoDelete" Scale="Medium">
                <DirectEvents>
                    <Click OnEvent="btnDelete_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnAddToGallery" Text="Thêm vào gallery" Icon="Add" Scale="Medium" Hidden="true">
                <DirectEvents>
                    <Click OnEvent="btnAddToGallery_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnAddToProduct" Text="Thêm vào sản phẩm" Icon="Add" Scale="Medium" Hidden="true">
                <DirectEvents>
                    <Click OnEvent="btnAddToProduct_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
        </Items>
    </ext:ButtonGroup>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <uc:MediaAddEdit runat="server" ID="MediaAddEdit1" />
    <ext:Store ID="Store1" runat="server" OnRefreshData="Store1_RefreshData" RemoteSort="true" RemotePaging="true">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="MediaID">
                <Fields>
                    <ext:RecordField Name="MediaID" Type="Auto" />
                    <ext:RecordField Name="Title" Type="String" />
                    <ext:RecordField Name="Tags" Type="String" />
                    <ext:RecordField Name="Description" Type="String" />
                    <ext:RecordField Name="Type" Type="String" />
                    <ext:RecordField Name="MediaURL" Type="String" />
                    <ext:RecordField Name="ThumbImage" Type="String" />
                    <ext:RecordField Name="IsEnabled" Type="Boolean" />
                    <ext:RecordField Name="DatetimeCreated" Type="Date" ServerMapping="Logs.DatetimeCreated" />
                </Fields>
            </ext:JsonReader>
        </Reader>
         <BaseParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="10" Mode="Raw" />
            <ext:Parameter Name="sort" Value="" />
            <ext:Parameter Name="dir" Value="" />
        </BaseParams>
        <SortInfo Field="MediaID" Direction="DESC" />
    </ext:Store>
    <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true" Title="Danh sách Media"
        StoreID="Store1">
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:Column Header="Mã" DataIndex="MediaID" Groupable="false" Width="20" Align="Center" />
                <ext:TemplateColumn Header="Preview" Width="30" Align="Center">
                    <Template runat="server">
                        <Html>
                            <%--<img width="64" hight="64" src="abc" onerror="getImagePreview(this,'{MediaURL}','{ThumbImage}','{Type}')" />--%>
                            <img width="64" hight="64" src="{ThumbImage}" />
                        </Html>
                    </Template>
                </ext:TemplateColumn>
                <ext:Column Header="Định dạng" DataIndex="Type" Width="30" Align="Center" />
                <ext:Column Header="Tiêu đề" DataIndex="Title" Groupable="false" />
                <ext:Column Header="Hiển thị" DataIndex="IsEnabled" Align="Center" Width="30">
                    <Renderer Handler="return (value) ? 'Có':'Không';" />
                </ext:Column>
                <ext:DateColumn Header="Ngày tạo" DataIndex="DatetimeCreated" Align="Center" Format="dd-MM-yyyy" Width="40"/>
            </Columns>
        </ColumnModel>
        <SelectionModel>
            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
        </SelectionModel>
        <View>
            <ext:GroupingView ID="GroupingView1" runat="server" ForceFit="true" MarkDirty="false"
                ShowGroupName="true" EnableNoGroups="true" HideGroupedColumn="true" ShowGroupsText="Nhóm lại theo cột này" />
        </View>
        <LoadMask ShowMask="true" />
        <Plugins>
            <ext:GridFilters runat="server" ID="GridFilters1">
                <Filters>
                    <ext:NumericFilter DataIndex="MediaID" />
                    <ext:ListFilter DataIndex="Type" Options="Image,Video,Flash,Audio" />
                    <ext:StringFilter DataIndex="Title" />
                    <ext:DateFilter DataIndex="DatetimeCreated">
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                    <ext:BooleanFilter DataIndex="IsEnabled" />
                </Filters>
            </ext:GridFilters>
        </Plugins>
        <BottomBar>
            <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" />
        </BottomBar>
    </ext:GridPanel>
    
</asp:Content>
